﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

using LowLevelGraphics;
using LowLevelGraphics.Forms;
using LowLevelGraphics.Filter;

using ImageRecognition2.Forms;
namespace ImageRecognition2.Action
{
    /// <summary>
    /// Action Dilation
    /// </summary>
    public class ActionDilation : AbstractCommand
    {
        protected PictureBox m_PictureBox = null;
        private Type m_Type = typeof(void);

        /// <summary>
        /// Initializes a new instance of the <see cref="ActionDilation"/> class.
        /// </summary>
        /// <param name="_type">The _type.</param>
        public ActionDilation(Type _type)
        {
            m_Type = _type;
        }

        internal ActionDilation(ActionDilation _ActionDilation)
        {
            this.m_Type = _ActionDilation.m_Type;
        }

        /// <summary>
        /// Runs the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void Run(object sender, EventArgs e)
        {
            FormMatrix parameter = new FormMatrix();
            if (parameter.ShowDialog() == DialogResult.OK)
            {
                Bitmap bitmap = (Bitmap)MainFormSingleton.ActivePictureBox.BackgroundImage;

                IFilter filter = (IFilter)Activator.CreateInstance(m_Type, (byte[,])parameter.ByteArray);
                UnsafeBitmap unsafeBitmap = filter.Execute(bitmap);
                unsafeBitmap.Dispose();
            }
        }

        public override object Clone()
        {
            return new ActionDilation(this);
        }
    }
}
